<?php

namespace App\Http\Controllers\WorkOrder;

use App\Http\Controllers\BaseController;
use App\Remote\FuYou\FuYouRemote;
use App\Service\FuYou\FuYouService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class FuYouController extends BaseController
{

    /**
     * test fuyou
     * @param Request $request
     * @return JsonResponse
     * @throws GuzzleException
     */
    public function index(Request $request): JsonResponse
    {
        $type         = $request->get('type') ?? 1;
        $mchntCd      = $request->get('mchntCd') ?? '0001000F8033495';
        $workOrderNo  = $request->get('workOrderNo') ?? 'KT00202211091727590207';
        $shopId       = $request->get('shopId') ?? '1';
        $FuYouRemote  = new FuYouRemote();
        $FuYouService = new FuYouService();
        if ($type == 1) {
            $res = $FuYouService->wxMchntAdd(['workOrderNo' => $workOrderNo, 'shopId' => $shopId]);//商户信息登记接口
        } elseif ($type == 'getMchntInfAndConfig') {
            $res = $FuYouRemote->getMchntInfAndConfig(['mchntCd' => $mchntCd]);//商户信息查询接口
        } elseif ($type == 'xyWechatConfigSet') {
            $res = $FuYouRemote->xyWechatConfigSet();//微信参数配置接口
        } elseif ($type == 'chnlSubMchIdQuery') {
            $res = $FuYouRemote->chnlSubMchIdQuery(['mchnt_cd' => $mchntCd]);//商户渠道子商户号查询接口
        } elseif ($type == 'wxAuthQuery') {
            $res = $FuYouRemote->wxAuthQuery(['mchnt_cd' => $mchntCd]);//微信认证查询接口
        } elseif ($type == 'aliQueryMchChnlInf') {
            $res = $FuYouRemote->aliQueryMchChnlInf(['mchnt_cd' => $mchntCd]);//商户查询支付宝渠道信息
        } elseif ($type == 'termCollect') {
            $res = $FuYouRemote->termCollect(['mchnt_cd' => $mchntCd]);//商户终端信息采集报备接口
        } elseif ($type == 'ftpUpImg') {
            $res = $FuYouRemote->ftpUpImg(['mchntCd' => $mchntCd]);//商户图片上传
        } elseif ($type == 'attachConfirm') {
            $res = $FuYouRemote->attachConfirm(['mchnt_cd' => $mchntCd]);//附件提交完成接口
        } elseif ($type == 'mchntOpenUpayQr') {
            $res = $FuYouRemote->mchntOpenUpayQr(['mchnt_cd' => $mchntCd]);//银联二维码业务申请开通接口
        } elseif ($type == 'wxMchntUpd') {
            $res = $FuYouService->wxMchntUpd($request->data);//商户信息修改接口
        } elseif ($type == 'mchntAcntUpd') {
            $res = $FuYouRemote->mchntAcntUpd($request->data);//入账信息变更接口
        } elseif ($type == 'wxMchntAdd') {
            $res = $FuYouRemote->wxMchntAdd($request->data);//入账信息变更接口
        } elseif ($type == 'wxMchntNameCheck') {
            $res = $FuYouRemote->wxMchntNameCheck($request->data);//商户名称判重接口
        } elseif ($type == 'xyWechatConfigGet') {
            $res = $FuYouRemote->xyWechatConfigGet($request->data);//商户名称判重接口
        } elseif ($type == 'actionFtpUpImg') {
            $res = $FuYouRemote->actionFtpUpImg($mchntCd);//ftp上传图片
        } elseif ($type == 'ftpUpImg2') {
            $res = $FuYouService->ftpUpImg(['mchnt_cd' => $mchntCd]);//ftp上传图片
        } elseif ($type == 'uploadImg') {
            $fileName = 'd2f8d0d0bfa8d5fdc3e6.jpg';

            $downPath = public_path() . '/storage/fuyou/' . $mchntCd;//文件路径
            $FuYouRemote->mkdirs($downPath);
            $FuYouRemote->downLoad('https://file.51kuafu.com/7b/af/b12530fff088a0486dbf58c3e96f1733e1800fefed63c9bea6a32d65c6bf.jpeg', $downPath, $fileName);

            $res = $FuYouRemote->uploadImg(['mchnt_cd' => $mchntCd, 'file_name' => $fileName, 'file' =>$downPath.'/'.$fileName]);//uploadImg
        } elseif ($type == 'mchntAcntUpdV2') {

            $res = $FuYouRemote->mchntAcntUpdV2(
                [
                    'fy_mchnt_cd'         => $mchntCd,
                    'dest_acnt_type'      => '02',                 // 需要更改的结算卡类型 01 对公，02对私，04双账户
                    'inter_bank_no_s'     => '325100058153',       // 对私入账卡开户行联行号见附件9 开户行信息列表
                    'prov_cd_s'           => '310',                // 对私省代码
                    'city_cd_s'           => '2900',               // 对私市代码
                    'iss_bank_nm_s'       => '招商银行',               // 对私入账卡开户行（在联行号找不到时生效）
                    'acnt_nm_s'           => '王三',                 // 对私入账卡户名
                    'acnt_no_s'           => '6222031404002280619',// 对私入账卡号
                    'acnt_artif_flag'     => 1,                    // 法人入账标识(0:非法人入账,1:法人入账若license_type=A，这此字段必须填：1:法人入账)
                    'card_bank_sc_img_id' => 'e71fdf93-500f-4f19-b545-88a48ee906bc',
                ]
            );//mchntAcntUpdV2
        }
        return $this->success($res);
    }

}
